﻿using HealthcareSystem.API.Write.Application.Command.TeamCommand;
using HealthcareSystem.Domain.BasicSettings.Team;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.TeamCommandHandler
{
    /// <summary>
    /// 团队修改请求
    /// </summary>
    public class UpdateTeamCommandHandler : IRequestHandler<UpdateTeamCommand, ApiResult<int>>
    {

        private readonly IBaseRepository<TeamTable> teamRep;

        public UpdateTeamCommandHandler(IBaseRepository<TeamTable> teamRep)
        {
            this.teamRep = teamRep;
        }
        public async Task<ApiResult<int>> Handle(UpdateTeamCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code=ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();
            
            var res=teamRep.GetAll().FirstOrDefault(x=>x.TeamId==request.TeamId);
            res.TeamName=request.TeamName;
            res.TeamProfile=request.TeamProfile;
            res.TeamStatus=request.TeamStatus;
            res.ParentTeam=request.ParentTeam;
            res.Charge=request.Charge;
            res.TeamTags = string.Join(",", request.TeamTags);
            res.Phone=request.Phone;
            await teamRep.UpdAsync(res);
            return await Task.FromResult(result);


        }
    }
}
